from PySide6.QtCore import Qt, Slot
from PySide6.QtWidgets import QHBoxLayout, QVBoxLayout, QApplication, QWidget
from qfluentwidgets import (
    MessageBoxBase,
    BodyLabel,
    InfoBarIcon,
    InfoBarPosition,
    SubtitleLabel,
    PushButton,
    FlyoutAnimationType,
    Flyout,
)
from qfluentwidgets.components.widgets.info_bar import InfoBar


class CopyableLabel(BodyLabel):
    def __init__(self, parent=None):
        super().__init__(parent)
        print(self.text())
        self.setMouseTracking(True)

    def mouseDoubleClickEvent(self, event):
        print(f"mouseDoubleClickEvent{self.text()}")
        clipboard = QApplication.clipboard()
        clipboard.setText(self.text())
        InfoBar(
            icon=InfoBarIcon.SUCCESS,
            title="Title",
            content="我的名字是吉良吉影，年龄 33 岁，只想过平静的生活。",
            orient=Qt.Horizontal,
            isClosable=True,
            position=InfoBarPosition.TOP_RIGHT,
            duration=2000,
            parent=self,
        )


class MsgLatOrLon(MessageBoxBase):
    def __init__(self, old_lat, old_lon, new_lat, new_lon, parent=None):
        super().__init__(parent)
        print(old_lat, old_lon, new_lat, new_lon)
        self.title = SubtitleLabel()
        self.title.setText("经纬度转换结果")
        self.title.setAlignment(Qt.AlignmentFlag.AlignCenter)

        self.label_lon = BodyLabel()
        self.label_lon.setText("经度：")
        self.old_label_lon = BodyLabel()
        self.old_label_lon.setText(str(old_lon))
        self.old_label_lon.setToolTip("经度")
        self.new_label_lon = CopyableLabel(self)
        self.new_label_lon.setText(str(new_lon))
        self.new_label_lon.setToolTip("经度\n双击复制")

        self.label_lat = BodyLabel()
        self.label_lat.setText("纬度：")
        self.old_label_lat = BodyLabel()
        self.old_label_lat.setText(str(old_lat))
        self.old_label_lat.setToolTip("纬度")
        self.new_label_lat = CopyableLabel(self)
        self.new_label_lat.setText(str(new_lat))
        self.new_label_lat.setToolTip("纬度\n双击复制")

        lon_layout = QHBoxLayout()
        lon_layout.addWidget(self.label_lon)
        lon_layout.addWidget(self.old_label_lon)
        lon_layout.addWidget(self.new_label_lon)

        lat_layout = QHBoxLayout()
        lat_layout.addWidget(self.label_lat)
        lat_layout.addWidget(self.old_label_lat)
        lat_layout.addWidget(self.new_label_lat)

        layout = QVBoxLayout()
        layout.addWidget(self.title)
        layout.addLayout(lon_layout)
        layout.addLayout(lat_layout)

        self.viewLayout.addLayout(layout)

        # 设置对话框的最小宽度
        self.widget.setMinimumWidth(350)

        # self.titleLabel = SubtitleLabel('打开 URL')
        # self.urlLineEdit = LineEdit()
        #
        # self.urlLineEdit.setPlaceholderText('输入文件、流或者播放列表的 URL')
        # self.urlLineEdit.setClearButtonEnabled(True)
        #
        # # 将组件添加到布局中
        # self.viewLayout.addWidget(self.titleLabel)
        # self.viewLayout.addWidget(self.urlLineEdit)


class Demo(QWidget):
    def __init__(self):
        super().__init__()
        self.button = PushButton("Click Me", self)
        self.button.clicked.connect(self.show_flyout)

        self.hBoxLayout = QHBoxLayout(self)
        self.hBoxLayout.addWidget(self.button, 0, Qt.AlignmentFlag.AlignCenter)
        self.resize(600, 500)

    @Slot()
    def show_flyout(self):
        Flyout.create(
            icon=InfoBarIcon.SUCCESS,
            title="Lesson 4",
            content="表达敬意吧，表达出敬意，然后迈向回旋的另一个全新阶段！",
            target=self.button,
            parent=self,
            isClosable=True,
            aniType=FlyoutAnimationType.PULL_UP,
        )


if __name__ == "__main__":
    import sys

    app = QApplication([])

    # 创建主窗口
    window = Demo()

    # 显示窗口
    window.show()

    # 运行应用
    sys.exit(app.exec())
